﻿function showUpdateForm() {
    $("#txtNewTitle").val($("#news_header").text());
    $("#txtNewImage").val($("#news_image").html());
    $("#txtNewDescription").val($("#news_description").text());
    $("#txtNewAuthor").val($("#news_info_2").text());
    $("#txtNewSource").val($("#news_info_3").text());
    tinyMCE.execCommand('mceInsertContent', false, $("#news_content").html());
    $("#form1").show();
    $("#news").css("display", "none");
}

function resetForm() {
    $("#form1").css("display", "none");
    $("#news").show();
}

function encodeString(str) {
    var sybl = new Array("&", ">", "\"", "'", "<");
    //var sybl = new Array("<", ">");
    var htmlname = new Array("&amp;", "&gt;", "&quot;", "&apos;", "&lt;");
    //var htmlname = new Array("&lt;", "&gt;");
    for (var i = 0; i < sybl.length; i++) {
        var reg = new RegExp(sybl[i], "g");
        str = str.replace(reg, htmlname[i]);
    }
    return str;
}

function decodeString(str) {
    var sybl = new Array("&", ">", "\"", "'", "<");
    //var sybl = new Array("<", ">");
    var htmlname = new Array("&amp;", "&gt;", "&quot;", "&apos;", "&lt;");
    //var htmlname = new Array("&lt;", "&gt;");
    for (var i = 0; i < sybl.length; i++) {
        var reg = new RegExp(htmlname[i], "g");
        str = str.replace(reg, sybl[i]);
    }
    return str;
}

function updateNews() {
    var p = $("#path").val();
    var t = escape($("#txtNewTitle").val());
    var i = escape($("#txtNewImage").val());
    var d = escape($("#txtNewDescription").val());
    var a = escape($("#txtNewAuthor").val());
    var s = escape($("#txtNewSource").val());
    var c = escape(tinyMCE.activeEditor.getContent({ format: 'text' }));

    $.ajax({
        url: "UpdateNews.aspx",
        type: "POST",
        dataType: "html",
        data: ({ path: p, txtNewTitle: t, txtNewImage: i, txtNewDescription: d, txtNewAuthor: a, txtNewSource: s, editor_content: c }),
        success: function(result) {
            xmlDoc = $.parseXML(result);
            $xml = $(xmlDoc);

            $("#news_header").html($xml.find("title").text());
            $("#news_image").html($xml.find("image").text());
            $("#news_description").html($xml.find("description").text());
            $("#news_content").html($xml.find("content").text());
            $("#news_info_1").html($xml.find("lastmoddate").text());
            $("#news_info_2").html($xml.find("author").text());
            $("#news_info_3").html($xml.find("source").text());

            $("#form1").css("display", "none");
            $("#news").show();
        }
    });
}
